package com.bwie.controller;

import com.bwie.config.NacosConfig;

import com.bwie.pojo.TbUser;
import com.bwie.service.TbUserService;
import com.bwie.utils.R;
import com.bwie.vo.AdminLoginVo;
import com.bwie.vo.PageInfoVo;
import com.bwie.vo.UserPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Author: Wrj
 * @Date: 2025/4/21 16:07
 * @Description:
 **/
@RestController
@RequestMapping("/user/index")
@RefreshScope
public class IndexController {

    @Autowired
    NacosConfig nacosConfig;
    @Autowired
    TbUserService tbUserService;


//
//    @Value("${site.ip}")
//    private String ip;

    /**
     * 根据id获取用户信息
     *
     * @param id
     * @return
     */
    @PostMapping("/getUserById/{id}")
    public R getUserById(@PathVariable(name = "id") Integer id) {

        return tbUserService.getUserById(id);
    }


    @PostMapping("/getConfig")
    public R getConfig(){
        System.out.println("className:"+nacosConfig.getClassName());
        return R.OK(nacosConfig.getClassName());
    }

//    @PostMapping("/getNacosIp")
//    public R getNacosIp(){
//        return R.OK("ip:"+ip);
//    }


    /**
     * 管理员登录
     * @param adminLoginVo
     * @return
     */
    @PostMapping("/adminlogin")
    public R adminlogin(@RequestBody AdminLoginVo adminLoginVo){

        return tbUserService.adminlogin(adminLoginVo);
    }


    @PostMapping("/getUserlist")
    public R getUserlist(@RequestBody PageInfoVo pageInfoVo){

        return tbUserService.getUserlist(pageInfoVo);
    }

    @PostMapping("/userReg")
    public R userReg(@RequestBody @Validated TbUser tbUser){

        return tbUserService.userReg(tbUser);
    }

    @PostMapping("/checkUser")
    public R checkUser(@RequestBody TbUser tbUser){
        return tbUserService.checkUser(tbUser);
    }

    @PostMapping("/getUserInfo")
    public R getUserInfo(){
        return tbUserService.getUserInfo();
    }

    @PostMapping("/updateUser")
    public R updateUser(@RequestBody TbUser tbUser){

        return tbUserService.updateUser(tbUser);
    }


    @PostMapping("/uploadFile")
    public R uploadFile(@RequestPart("file")MultipartFile file){
        return tbUserService.uploadFile(file);
    }

    @PostMapping("/deleteUserById/{userId}")
    public R deleteUserById(@PathVariable(name = "userId") Integer userId){
        return tbUserService.deleteUserById(userId);
    }

    @PostMapping("/deleteAll")
    public R deleteAll(@RequestBody List<TbUser> userList){
        return tbUserService.deleteAll(userList);
    }

    /**
     * 获取当前用户的角色列表
     * @return
     */
    @PostMapping("/getMyRolelist")
    public R getMyRolelist(){
        return tbUserService.getMyRolelist();
    }

    @PostMapping("/getUserMenuTree")
    public R getUserMenuTree(){
        return tbUserService.getUserMenuTree();
    }



    /**
     * 分页获取用户列表（数据来源于es）
     */
    @PostMapping("/getUserListsFormEs")
    public R getUserListsFormEs(@RequestBody UserPageVo userPageVo){
        return tbUserService.getUserListsFormEs(userPageVo);

    }
}
